package com.omg.persistence.delegate.lifepoint;

import java.util.List;

import com.ibatis.dao.client.DaoManager;
import com.omg.persistence.dao.lifepoint.DaoConfig;
import com.omg.persistence.dao.lifepoint.entity.LPMessage;
import com.omg.persistence.dao.lifepoint.iface.LPMessageDao;

public class LPMessageDelegate {

	private static volatile LPMessageDelegate instance;
	private LPMessageDao lpMessageDao;
	private static final Object synObj = new Object();

	public static LPMessageDelegate getInstance() {
		if (instance == null) {
			instance = new LPMessageDelegate();
		}
		return instance;
	}

	private LPMessageDelegate() {
		synchronized (synObj) {
			DaoManager daoMgr = DaoConfig.getDaoManager();
			this.lpMessageDao = (LPMessageDao) daoMgr
					.getDao(LPMessageDao.class);
		}
	}

	public int addLPMessage(LPMessage lpMessage) {
		return this.lpMessageDao.addLPMessage(lpMessage);
	}

	public LPMessage getLPMessage(String messageid) {
		return this.lpMessageDao.getLPMessage(messageid);
	}

	public int delLPMessage(String messageid) {
		return this.lpMessageDao.delLPMessage(messageid);
	}

	public int addOrReplaceLPMessage(LPMessage lpMessage) {
		this.lpMessageDao.delLPMessage(lpMessage.getMessageid());
		return this.addLPMessage(lpMessage);
	}

	public List<LPMessage> getLPMessageByUserid(String userid) {
		return this.lpMessageDao.getLPMessageByUserid(userid);
	}

}
